<?php
	class FlinkAction extends CommonAction {
		private $fLink;
		function __construct(){
			parent::__construct();
			$this->fLink=new FlinkModel();
		}
		function  add($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息,LOGO选项为链接网站的LOGO图片所在位置. ');
			}else{
				$this->message($status,$tmess);
			}
			if($_POST["list"]){
				$this->assign("webl", "checked");
			}else{
				$this->assign("webn", "checked");
			}
			$this->assign("post", $_POST);	
			$this->display("admin/flink/add.tpl");
		}

		function insert(){
			$_POST["dtime"]=time();
			if($this->fLink->validateForm()){
				if($this->fLink->add($_POST)){
					$_POST=array();
					$this->add("友情链接添加成功",1);
				
				}else{
					$this->add("友情链接添加失败.",0);
				}
			}else{
				$this->add($this->fLink->getMessList(),0);
			}

		}


		function edit($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '可以通过输入整数改变友情链接在首页中的显示顺序,从小到大的排列顺序.');
			}else{
				$this->message($status,$tmess);
			}
		
			$page=new Page("admin.php?m=flink&a=edit&",$this->fLink->total(), ARTICLE_PAGE_SIZE);	
		        
			$allLinks=$this->fLink->findAll(array("id, webName, url, dtime,ord"),$page->getOffset(), ARTICLE_PAGE_SIZE);
			$this->assign("links", $allLinks);
			$this->assign("page", isset($_GET["page"])?$_GET["page"]:1);
			$this->assign("fpage", $page->getPage());
		
			$this->display("admin/flink/edit.tpl");
		}
		function del(){
			if($this->fLink->del($_GET["id"])){
				$this->edit("删除友情链接成功！",1);
			}else{
				$this->edit("删除友情链接失败！",0);
			}
		}

		function order(){
			if($this->fLink->modOrder($_POST["linkOrder"], $_POST["linkIds"])){
				$this->edit("友情链接显示顺序成功！",1);
			}else{
				$this->edit("友情链接显示顺序失败！",0);
			}
			
		}
		function mod($tmess=null,$status=1){
			if(empty($tmess)){
					$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息,LOGO选项为链接网站的LOGO图片所在位置. ');
			}else{
				$this->message($status,$tmess);
			}

			if($status){
				$flink=$this->fLink->find($_REQUEST["id"]);
				$this->assign("post", $flink);
			
			}else{
				$flink=$_POST;
			}
			if($flink["list"]){
				$this->assign("webl", "checked");
			}else{
				$this->assign("webn", "checked");
			}
			$this->assign("post", $flink);
			$this->display("admin/flink/mod.tpl");
		}

		function update(){
			if($this->fLink->validateForm()){
				if($this->fLink->mod($_POST)){
					$this->mod("修改成功",1);
				}else{
					$this->mod("修改失败",0);
				}	 
			}else{
				$this->mod($this->fLink->getMessList(), 0);
			}		
		
		
		}


	}
